using Gateway.Common.Enums;
using Gateway.Domain.EFCore.Configuration;
using Gateway.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Gateway.Domain.Configuration;

public class UserMessageConfiguration : AggregateRootEntityConfiguration<UserMessage>
{
    public override void Configure(EntityTypeBuilder<UserMessage> builder)
    {
        builder.ToTable(t => t.HasComment("用户消息"));
        base.Configure(builder);
        builder.Property(x => x.Account).IsRequired().HasMaxLength(50).HasComment("账号");
        builder.Property(x => x.Message).HasColumnType("text").HasComment("消息内容");
        builder.Property(x => x.Sender).IsRequired().HasMaxLength(50).HasComment("发送人");
        builder.Property(x => x.Intro).IsRequired().HasMaxLength(50).HasComment("摘要");
        builder.Property(x => x.SendType).HasMaxLength(200).HasComment("消息类型");
        builder.Property(x => x.ReadStatus).IsRequired().HasMaxLength(1).HasComment("是否已读Y已读 N 未读")
            .HasConversion(x => x.Value, x => BooleanStatusEnum.FromValue(x));
        builder.Property(x => x.State).IsRequired().HasMaxLength(1).HasComment("消息完成状态 S 成功  F 失败  D 执行中")
            .HasConversion(x => x.Value, x => MessageStateEnum.FromValue(x));
        builder.Property(x => x.MessageType).IsRequired().HasMaxLength(10).HasComment("任务类型 NOTIFY 通知 TASK 任务")
            .HasConversion(x => x.Value, x => MessageTypeEnum.FromValue(x));
        builder.Property(x => x.Result).HasMaxLength(500).HasComment("结果 可以是附件地址");
        builder.Property(x => x.ResourceId).HasMaxLength(500).HasComment("关联的资源id");
    }
}